package com.zy.net

import com.zy.net.data.DataRecord
import com.zy.net.retrofit.RetrofitNetServiceImpl
import okhttp3.Callback
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request
import okhttp3.Response

class NetServiceImpl(private val impl: NetServiceInterface) : NetServiceInterface {
    companion object {
        //val INSTANCE = NetServiceImpl(OkHttpNetServiceImpl())
        val INSTANCE = NetServiceImpl(RetrofitNetServiceImpl())

        val JSON: MediaType = "application/json; charset=utf-8".toMediaType()

        const val HOST = "http://192.168.0.8:8866"

        const val UPDATE_URL = "$HOST/zy/world/add_record"
        const val GET_ALL = "$HOST/zy/world/all"
    }

    override fun request(request: Request, responseCallback: Callback) =
        impl.request(request, responseCallback)


    override fun request(url: String, responseCallback: Callback) =
        impl.request(url, responseCallback)


    override fun execute(url: String): Response = impl.execute(url)


    override fun execute(request: Request) = impl.execute(request)


    override fun getAllStr(callback: retrofit2.Callback<String>) {
        impl.getAllStr(callback)
    }

    override fun getAll(callback: retrofit2.Callback<DataRecord>) {
        impl.getAll(callback)
    }
}